package com.gitee.wsl.net.token.bean

import com.gitee.wsl.ext.base.currentTime
import com.gitee.wsl.net.token.identity.Identity
import com.gitee.wsl.struct.generator.randomUUID
import kotlinx.datetime.Instant
import kotlin.time.Duration.Companion.seconds

data class RefreshToken(
    val refreshToken: String,
    override val expireTime: Instant,
    val identity: Identity?,
    val clientId: String,
    val scopes: Set<String>
) : ExpirableToken {
    companion object{
        fun refreshTokenExpireInSeconds(identity: Identity?,
                                        clientId: String,
                                        requestedScopes: Set<String>,
                                        refreshTokenExpireInSeconds: Int = 86400
        ) = RefreshToken(
            randomUUID(),
            currentTime + refreshTokenExpireInSeconds.seconds,
            identity,
            clientId,
            requestedScopes
        )
    }
}